package com.blog4j.server.modules.inner;

import com.blog4j.api.client.FeignServer;
import com.blog4j.api.vo.NoticeEmailVo;
import com.blog4j.common.model.LogVo;
import com.blog4j.server.modules.email.service.EmailService;
import com.blog4j.server.modules.log.service.LogService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 98k灬
 * @version v1.0.0
 * @Description : 功能描述
 * @Create on : 2024/8/19 19:52
 **/
@RestController
@RequestMapping("/feign")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ServerFeignController implements FeignServer {
    private final EmailService emailService;
    private final LogService logService;

    /**
     * 发送邮件给文章审批人
     *
     * @param emailVo 邮件信息
     */
    @Override
    public void sendSystemEmailToArticleApproveUser(NoticeEmailVo emailVo) {
        emailService.sendSystemEmailToArticleApproveUser(emailVo);
    }

    /**
     * 发送邮件给文章创建者
     *
     * @param toEmail 接收方邮箱地址
     * @param articleTitle 文章标题
     */
    @Override
    public void sendSystemEmailToArticleCreater(@RequestParam("toEmail") String toEmail,
                                                @RequestParam("articleTitle") String articleTitle) {
        emailService.sendSystemEmailToArticleCreater(toEmail, articleTitle);
    }

    /**
     * 给组织管理员发送邮件
     *
     * @param emailVo 邮件信息
     */
    @Override
    public void sendSystemEmailToOrganizationAdmin(NoticeEmailVo emailVo) {
        emailService.sendSystemEmailToOrganizationAdmin(emailVo);
    }

    /**
     * 用户申请加入组织，审批后，给用户发送邮件通知
     *
     * @param toEmail          用户邮箱地址
     * @param organizationName 组织名称
     */
    @Override
    public void sendEmailToUser(String toEmail, String organizationName) {
        emailService.sendEmailToUser(toEmail, organizationName);
    }

    /**
     * 给超级管理员发送审批组织的邮件
     *
     * @param emailVo 邮件信息
     */
    @Override
    public void sendSystemEmailToSuperAdmin(NoticeEmailVo emailVo) {
        emailService.sendSystemEmailToSuperAdmin(emailVo);
    }

    /**
     * 用户申请创建组织 审批后 给用户发送邮件
     *
     * @param toEmail          用户邮箱地址
     * @param organizationName 组织名称
     */
    @Override
    public void sendEmailToUserForApproveOrganization(String toEmail, String organizationName) {
        emailService.sendEmailToUserForApproveOrganization(toEmail, organizationName);
    }

    /**
     * 添加日志
     *
     * @param logVo 日志信息
     */
    @Override
    public void addLog(LogVo logVo) {
        logService.addLog(logVo);
    }
}
